<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加合同费用条款</title>
    <link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <style>
        .inpText{
            width: 100px !important;
            display: inline-block !important;
        }
    </style>
</head>

<body class="white-bg" style="padding: 3px;font-size: 13px">
    <form action="{:url('Contractcostterms/addmaintainterms')}" class="form-inline" id="form1" method="post">
        <input type="hidden" name="termsid" value="{$termsid}">
        <input type="hidden" name="id" value="{if isset($data)}{$data.id}{/if}">
        <table class="table table-bordered bud_hei">
            <tr>
                <td style="width: 140px" class="text-right">费用科目<span class="colorRed">*</span>：</td>
                <td>
                    <select name="subject" class="form-control" style="width:30%">
                        <option value="0" {if (isset($data.subject)&&($data.subject==0))}checked{/if}>有条件返利费</option>
                        <option value="1" {if (isset($data.subject)&&($data.subject==1))}checked{/if}>无条件返利费</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 140px" class="text-right">控制类型<span class="colorRed">*</span>：</td>
                <td>
                    <label class="pressSall">
                        <input type="radio" name="controlType" value="0" {if (isset($data)&&$data.controlType==0)||!isset($data)}checked{/if} id="pressSall">
                        按销售额控制
                    </label>
                    <label class="pressSallAim">
                        <input type="radio" name="controlType" value="1"{if (isset($data.controlType)&&($data.controlType==1))}checked{/if} id="pressSallAim">
                        按销售目标达成率控制
                    </label>
                    <label class="noTerm">
                        <input type="radio" name="controlType" value="2" {if (isset($data.controlType)&&($data.controlType==2))}checked{/if} id="noTerm">
                        无条件返利
                    </label>
                    <label class="noTerm">
                        <input type="radio" name="controlType" value="3" {if (isset($data.controlType)&&($data.controlType==3))}checked{/if} id="noTerm">
                        固定费用
                    </label>
                </td>
            </tr>
            <tr>
                <td style="width: 140px" class="text-right">处理方式<span class="colorRed">*</span>：</td>
                <td>
                    <label class="handler">
                        <input type="radio" name="processWay" {if (isset($data)&&$data.processWay==0)||!isset($data)}checked{/if}  value="0" id="handler">
                        手动
                    </label>
                    <label class="automatic">
                        <input type="radio" name="processWay" {if (isset($data.processWay)&&($data.processWay==1))}checked{/if} value="1" id="automatic">
                        自动预提
                    </label>
                    <label class="WrittOff">
                        <input type="radio" name="processWay" {if (isset($data.processWay)&&($data.processWay==2))}checked{/if} value="2" id="WrittOff">
                        自动预提并核销
                    </label>
                    <label class="outLend">
                        <input type="radio" name="processWay" {if (isset($data.processWay)&&($data.processWay==3))}checked{/if} value="3" id="outLend">
                        外部导入
                    </label>
                </td>
            </tr>
            <tr>
                <td style="width: 140px" class="text-right">频率<span class="colorRed">*</span>：</td>
                <td>
                    <label class="oneMonth">
                        <input type="radio" name="Frequency" {if (isset($data)&&$data.Frequency==0)||!isset($data)}checked{/if} value="0" id="oneMonth">
                        1个月
                    </label>
                    <label class="threeMonth">
                        <input type="radio" name="Frequency" {if (isset($data)&&($data.Frequency==1))}checked{/if} value="1" id="threeMonth">
                        3个月
                    </label>
                    <label class="sixMonth">
                        <input type="radio" name="Frequency" {if (isset($data)&&($data.Frequency==2))}checked{/if} value="2" id="sixMonth">
                        6个月
                    </label>
                    <label class="twelveMoth">
                        <input type="radio" name="Frequency" {if (isset($data)&&($data.Frequency==3))}checked{/if} value="3" id="twelveMoth">
                        12个月
                    </label>
                    <label class="notApplicable">
                        <input type="radio" name="Frequency" {if (isset($data)&&($data.Frequency==4))}checked{/if} value="4" id="notApplicable">
                        不适用
                    </label>
                </td>
            </tr>
            <tr>
                <td class="text-right" style="width: 140px">支付方式：</td>
                <td>
                    <select name="paymethod" id="paymethod" class="form-control" style="width:30%">
                        <option value="0" >请选择</option>
                        <option value="1"{if (isset($data)&&($data.paymethod==1))}selected{/if}>转账</option>
                        <option value="2"{if (isset($data)&&($data.paymethod==2))}selected{/if}>事后补货</option>
                        <option value="3"{if (isset($data)&&($data.paymethod==3))}selected{/if}>账扣</option>
                        <option value="4"{if (isset($data)&&($data.paymethod==4))}selected{/if}>票扣</option>
                        <option value="5"{if (isset($data)&&($data.paymethod==5))}selected{/if}>事前货补</option>
                        <option value="6"{if (isset($data)&&($data.paymethod==6))}selected{/if}>折扣</option>
                    </select>


                </td>
            </tr>
            <tr>
                <td class="text-right" style="width: 140px">具体费用构成信息<span class="colorRed">*</span>：<br>
                    <button type="button" class="btn btn-info btn-sm" id="addKanJi">添加坎级</button>
                </td>
                <td style="padding:1px">
                    <table class="table table-bordered bud_hei" id="infoTab" style="margin-bottom: 0">
                        <thead>
                            <tr class="info">
                                <th class="text-center">序号</th>

                                <th class="text-center">坎级</th>
                                <th class="text-center">返利%</th>
                                <th class="text-center">返固定额</th>
                                <th class="text-center">操作</th>
                            </tr>
                        </thead>
                        <tbody id="tabBody">



                        {volist name="info" id="list"}

                        {if condition="($i == 1) "}  <!--第一个-->
                        <tr id="first">
                            <td>
                                <input type="hidden" name="num[]" value="1">
                                第{$i}级
                            </td>
                            <td>
                                    <span class="sallAim">
                                    <input type="hidden" name="start[]" value="-∞">-∞元≤值<
                                    <input type="text" name="end[]" value="{$list.end}" class="form-control inpText">元
                                </span>
                                <span class="sallControl" style="display:none">
                                    <input type="hidden" name="startjq[]" value="-∞">-∞%≤值<
                                    <input type="text" name="endjq[]" value="{$list['endjq']}" class="form-control inpText">%
                                </span>
                            </td>
                            <td>
                                <input type="text" name="flzb[]" value="{$list['flzb']}" class="form-control inpText">%
                            </td>
                            <td>
                                <input type="text" name="fljq[]" value="{$list['fljq']}" class="form-control" style="display:inline-block;width:120px">元
                            </td>
                            <td>
                            </td>
                        </tr>

                        {elseif condition="$i eq $num"/} <!--最后一个-->
                        <tr id="last">
                            <td>
                                <input type="hidden" name="num[]" value="2">
                                第{$i}级
                            </td>
                            <td>
                                    <span class="sallAim">
                                    <input type="text" name="start[]" value="{$list.start}" class="form-control inpText">元≤值<+∞
                                    <input type="hidden" name="end[]"  value="+∞">
                                    </span>
                                <span class="sallControl" style="display:none">

                                    <input type="text" name="startjq[]" value="{$list.startjq}" class="form-control inpText">%≤值<+∞
                                    <input type="hidden" name="endjq[]"  value="+∞">%
                                    </span>
                            </td>
                            <td>

                                <input type="text" name="flzb[]" value="{$list.flzb}" class="form-control inpText">%
                            </td>
                            <td>
                                <input type="text" name="fljq[]" value="{$list.fljq}" class="form-control" style="display:inline-block;width:120px">元
                            </td>
                            <td>
                            </td>
                        </tr>
                        {else /}  <!--中间的-->
                        <tr >
                            <td>
                                <input type="hidden" name="num[]" value="2">
                                第{$i}级
                            </td>
                            <td>
                                    <span class="sallAim">
                                    <input type="text" name="start[]" value="{$list.start}" class="form-control inpText">元≤值<
                                    <input type="text" name="end[]"  value="{$list.end}" class="form-control inpText">元
                                    </span>
                                <span class="sallControl" style="display:none">

                                    <input type="text" name="startjq[]" value="{$list.startjq}" class="form-control inpText">%≤值<
                                    <input type="text" name="endjq[]" value="{$list.endjq}" class="form-control inpText">%
                                    </span>
                            </td>
                            <td>
                                <input type="text" name="flzb[]"  value="{$list.flzb}" class="form-control inpText">%
                            </td>
                            <td>
                                <input type="text" name="fljq[]"  value="{$list.fljq}" class="form-control" style="display:inline-block;width:120px">元
                            </td>
                            <td>
                                <a href="javascript:;" class="delThis">删除</a>
                            </td>
                        </tr>

                        {/if}
                        {/volist}
                        {if (isset($info)&&empty($info))}
                            <tr id="first">
                                <td>
                                    <input type="hidden" name="num[]" value="1">
                                    第1级
                                </td>
                                <td>
                                    <span class="sallAim">
                                    <input type="hidden" name="start[]" value="-∞">-∞元≤值<
                                    <input type="text" name="end[]" class="form-control inpText">元
                                </span>
                                    <span class="sallControl" style="display:none">
                                    <input type="hidden" name="startjq[]" value="-∞">-∞%≤值<
                                    <input type="text" name="endjq[]" class="form-control inpText">%
                                </span>
                                </td>
                                <td>
                                    <input type="text" name="flzb[]" class="form-control inpText">%
                                </td>
                                <td>
                                    <input type="text" name="fljq[]" class="form-control" style="display:inline-block;width:120px">元
                                </td>
                                <td>
                                </td>
                            </tr>

                            <tr id="last">
                                <td>
                                    <input type="hidden" name="num[]" value="2">
                                    第2级
                                </td>
                                <td>
                                    <span class="sallAim">
                                    <input type="text" name="start[]" class="form-control inpText">元≤值<+∞
                                    <input type="hidden" name="end[]"  value="+∞">
                                    </span>
                                    <span class="sallControl" style="display:none">

                                    <input type="text" name="startjq[]" class="form-control inpText">%≤值<+∞
                                    <input type="hidden" name="endjq[]"  value="+∞">%
                                    </span>
                                </td>
                                <td>

                                    <input type="text" name="flzb[]" class="form-control inpText">%
                                </td>
                                <td>
                                    <input type="text" name="fljq[]" class="form-control" style="display:inline-block;width:120px">元
                                </td>
                                <td>
                                </td>
                            </tr>
                        {/if}
                        </tbody>
                    </table>
                    <div id="threeInfo" style="display:none">
                        <input type="text" name="fee" value="{if (isset($data))}{$data.fee}{/if}" class="form-control inpText">%
                    </div>
                    <div id="fourInfo" style="display:none">
                        <input type="text" name="feejq" value="{if (isset($data))}{$data.feejq}{/if}" class="form-control inpText">元
                    </div>
                </td>
            </tr>
            <tr><td  colspan="3">说明：设置的坎级必须包含所有数字逻辑范围且不允许坎级之间有交叉或者有空缺，因此，第一级默认-∞，最后一级默认+∞，同时上一级的'<值'必须等于下一级的'≥值'。</td></tr>
            <tr>

                <td style="width: 140px" class="text-right">备注说明：</td>
                <td>
                    <textarea name="des"  cols="70" rows="4" class="form-control"> {if (isset($data))}{$data.des}{/if}</textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="text-center">
                    <!--<button type="submit" class="btn btn-success btn-sm">保存</button>
                    &nbsp; &nbsp; &nbsp; &nbsp;
                    <button type="button" class="btn btn-default btn-sm">返回</button>-->
                    <input type="button" class="btn btn-primary" value="提交" onclick="primary()"/><span class="lr_5"></span>
                    <input type="button" class="btn btn-warning" onclick="back()" value="返回"/>
                </td>
            </tr>
        </table>
    </form>
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js"></script>
    <script src="__STATIC__/layout/js/contabs_sub.js"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
    <!-- Sweet alert -->
    <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script src="__STATIC__/layout/js/contabs_sub.js"></script>
    <script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
    <script>
    $(function() {
        $('body').on('click', 'input[type=text]', function() {
            this.select()
        })
        $("#tabBody").find('tr:first').find("td:last").text('')
    });

    /*日期范围限制*/

    $("input[name='controlType']").click(function(event) {
        // alert($(this).val())
        if ($(this).val() == 0) {
            $("#infoTab").show();
            $(".sallAim").css('display', 'inline');
            $(".sallControl").css('display', 'none');
            $("#threeInfo").hide()
            $("#fourInfo").hide()
            $("#addKanJi").show()
        } else if ($(this).val() == 1) {
            $("#infoTab").show();
            $(".sallAim").css('display', 'none');
            $(".sallControl").css('display', 'inline');
            $("#threeInfo").hide()
            $("#fourInfo").hide()
            $("#addKanJi").show()
        } else if ($(this).val() == 2) {
            $("#infoTab").hide();
            $("#threeInfo").show()
            $("#fourInfo").hide()
            $("#addKanJi").hide()
        } else {
            $("#infoTab").hide();
            $("#threeInfo").hide()
            $("#fourInfo").show()
            $("#addKanJi").hide()
        }
    });


    /*添加坎级*/
    $("#addKanJi").click(function() {
        var val=$("#tabBody #last").find('input').first().val();
        var val2=$("#tabBody #last").find('input').eq(1).val();
        var val3=$("#tabBody #last").find('input').eq(3).val();
        console.log(val,'val')
        console.log(val3,'val3')
        var str='<tr>\n' +
            '<td>\n' +
            '                                    <input type="hidden" name="num[]" value='+val+'>\n' +
            '                                    第'+val+'级\n' +
            '                                </td>'+
            '                                <td>\n' +
            '                                    <span class="sallAim">\n' +
            '                                    <input type="text" name="start[]" class="form-control inpText" value='+val2+'>元≤值<\n' +
            '                                    <input type="text" name="end[]" class="form-control inpText">元\n' +
            '                                </span>\n' +
            '                                    <span class="sallControl" style="display:none">\n' +
            '                                    <input type="text" name="startjq[]" class="form-control inpText"  value='+val3+'>%~\n' +
            '                                    <input type="text" name="endjq[]" class="form-control inpText">%\n' +
            '                                </span>\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input type="text" name="flzb[]" class="form-control inpText">%\n' +
            '                                </td>\n' +
            '                                <td>\n' +
            '                                    <input type="text" name="fljq[]" class="form-control" style="display:inline-block;width:120px">元\n' +
            '                                </td>\n' +
            '                                <td><a href="javascript:;" class="delThis">删除</a>\n' +
            '                                </td>\n' +
            '                            </tr>';
        val=parseInt(val)+1;
        $("#tabBody #last").before(str);
        var str=
            '                                    <input type="hidden" name="num[]" value='+val+'>\n' +
            '                                    第'+val+'级\n';
        var val=$("#tabBody #last").find('td').first().html(str);

        //var val2=$("#tabBody #last").find('td').eq(3).html(str);
        $("#tabBody #last").find('input').eq(1).val('');
        $("#tabBody #last").find('input').eq(3).val('');


        var controlType = $("input[name='controlType']:checked").val();
        console.log(controlType,'control2Type')
        if(controlType==0){
            $(".sallAim").css('display', 'inline');
            $(".sallControl").css('display', 'none');
        }else {
            $(".sallAim").css('display', 'none');
            $(".sallControl").css('display', 'inline');
        }





       /* var str = $("#tabBody").find('tr:first').clone()
        console.log(str,'str')
        $("#tabBody").append(str);
        $("#tabBody tr:last").find('td').find('input').val('');
        $("#tabBody tr:not(:first)").each(function(index, el) {
            if ($(this).find("td:last").text() == "") {
                $(this).find("td:last").append('<a href="javascript:;" class="delThis">删除</a>')
            } 
        });*/



    })
   
    $(document).on('click','.delThis',function(){
        var tr= $('table#table1 tr').index(this);
        /*console.log(tr,'tr')*/


        var tr= $(this).parent('td').parent('tr')
        var obj={};
        var num =$(tr).children("td").eq(0).text();

        //$(this).parent().prevAll().length + 1;
        var rows2 = $(this).parent('td').parent('tr').prevAll().length + 1;

        console.log(rows2,'rows2')
        /*obj.index=$(tr).children("td").eq(0).text();
        obj.name=$(tr).children("td").eq(1).text();*/

        $(this).parent('td').parent('tr').remove()  //删除本行


        var table =document.getElementById("tabBody");
        var rows = table.rows.length;
        var k=rows-1;
        $("#tabBody ").find('tr').eq(k).find('input').eq(2).val();
        console.log()

        for(var i = rows2; i <= rows; i++) {
            console.log(i,'i')
            if(i == rows2){
                var l=k-1;
                var m=l-1;
                var num1=  $("#tabBody ").find('tr').eq(m).find('input').eq(2).val();
               var num2= $("#tabBody ").find('tr').eq(l).find('input').eq(1).val();
                $("#tabBody ").find('tr').eq(l).find('input').eq(1).val(num1);
                console.log(num1,'num1')
                console.log(num2,'num2')
            }

            str='                                    <input type="hidden" name="num[]" value='+i+'>\n' +
                '                                    第'+i+'级\n' +
                '                                </td>';
j=i-1;
            //$("#tabBody ").find('tr').eq(j).find('td').eq(0).html(str);


            $("#tabBody ").find('tr').eq(j).find('td').eq(0).html(str);

        }console.log(rows,'rows')
    })


    var controlTypeval={$controlTypeval};
    if(controlTypeval==1){
        $("#infoTab").show();
        $(".sallAim").css('display', 'none');
        $(".sallControl").css('display', 'inline');
        $("#threeInfo").hide()
        $("#fourInfo").hide()
        $("#addKanJi").show()
    }else if(controlTypeval==2){
        $("#infoTab").hide();
        $("#threeInfo").show()
        $("#fourInfo").hide()
        $("#addKanJi").hide()
    }else if(controlTypeval==3){
        $("#infoTab").hide();
        $("#threeInfo").hide()
        $("#fourInfo").show()
        $("#addKanJi").hide()
    }else if(controlTypeval==3){

    }

    console.log('controlTypeval',controlTypeval)



    function primary(){

        $('form').submit();
    }

    function back() {
        history.go(-1)
    }
    </script>
</body>

</html>